package com.maori.languageapp.fragments;

import java.io.File;

import com.maori.languageapp.R;
import com.maori.languageapp.Maori_Categories;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;

public class Maori_Fragment_Discover extends Fragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View view = inflater.inflate(R.layout.maori_fragment_discover, null);

		RelativeLayout captureWord = (RelativeLayout) view
				.findViewById(R.id.discover_word);
		RelativeLayout capturePhrase = (RelativeLayout) view
				.findViewById(R.id.discover_phrase);
		RelativeLayout captureStory = (RelativeLayout) view
				.findViewById(R.id.discover_story);
		RelativeLayout captureSong = (RelativeLayout) view
				.findViewById(R.id.discover_songs);
		RelativeLayout captureIdiom = (RelativeLayout) view
				.findViewById(R.id.discover_idioms);

		// Display Option
		// Display_Types 1 Discover ***** Index : 100
		// Display_Types 2 Capture ***** Index : 200
		// Display_Types 3 Curate ***** Index : 300

		captureWord.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg) {
				// Intent i = new Intent(getActivity(),
				// Maori_Capture_Word.class);
				Intent i = new Intent(getActivity(), Maori_Categories.class);
				i.putExtra("Display_Type", "100");
				i.putExtra("Capture_Type", "1");
				i.putExtra("Category", "DISCOVER");
				startActivity(i);
				getActivity().finish();
			}
		});
	
		capturePhrase.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg) {
				// Intent i = new Intent(getActivity(),
				// Maori_Capture_Phrase.class);
				Intent i = new Intent(getActivity(), Maori_Categories.class);
				i.putExtra("Display_Type", "100");
				i.putExtra("Capture_Type", "2");
				i.putExtra("Category", "DISCOVER");
				startActivity(i);
				getActivity().finish();
			}
		});

		captureStory.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg) {
				// Intent i = new Intent(getActivity(),
				// Maori_Capture_Story.class);
				Intent i = new Intent(getActivity(), Maori_Categories.class);
				i.putExtra("Display_Type", "100");
				i.putExtra("Capture_Type", "3");
				i.putExtra("Category", "DISCOVER");
				startActivity(i);
				getActivity().finish();
			}
		});

		captureSong.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg) {
				// Intent i = new Intent(getActivity(),
				// Maori_Capture_Song.class);
				Intent i = new Intent(getActivity(), Maori_Categories.class);
				i.putExtra("Display_Type", "100");
				i.putExtra("Capture_Type", "4");
				i.putExtra("Category", "DISCOVER");
				startActivity(i);
				getActivity().finish();
			}
		});

		captureIdiom.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg) {
				// Intent i = new Intent(getActivity(),
				// Maori_Capture_Idiom.class);
				Intent i = new Intent(getActivity(), Maori_Categories.class);
				i.putExtra("Display_Type", "100");
				i.putExtra("Capture_Type", "5");
				i.putExtra("Category", "DISCOVER");
				startActivity(i);
				getActivity().finish();
			}
		});

		return view;
	}

	// ***********Memory Handling****************
	@Override
	public void onStop() {
		super.onStop();
	}

	// Fires after the OnStop() state
	@Override
	public void onDestroy() {
		super.onDestroy();
		try {
			trimCache(this);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void trimCache(Maori_Fragment_Discover maori_Fragment_Discover) {
		try {
			File dir = maori_Fragment_Discover.getCacheDir();
			if (dir != null && dir.isDirectory()) {
				deleteDir(dir);
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	private File getCacheDir() {
		// TODO Auto-generated method stub
		return null;
	}

	public static boolean deleteDir(File dir) {
		if (dir != null && dir.isDirectory()) {
			String[] children = dir.list();
			for (int i = 0; i < children.length; i++) {
				boolean success = deleteDir(new File(dir, children[i]));
				if (!success) {
					return false;
				}
			}
		}

		// The directory is now empty so delete it
		return dir.delete();
	}

	void OnBackStackChangedListener() {

	}
}
